"""
Market Information window

TODO: Just had the idea to call this module "System Status"
"""

from PyQt4.QtCore import *
from PyQt4.QtGui import *
import types

import ui_w_marketinfo
import system.navalasystem as na
from misc import misc

try:
    _fromUtf8 = QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s


class MarketInfo(QMainWindow, ui_w_marketinfo.Ui_MarketInfo):
    def __init__(self, parent=None):
        super(MarketInfo, self).__init__(parent)
        self.setupUi(self)
        self.AddItems()
        self.resize(1, 1) # As small as possible!
        self.UpdateGUI()
        
    def UpdateGUI(self):
        """Updates status controls based on system status."""
        if na.vala.flagOpenMarket:
            s = "<font color=green>Open</font>"
        else:
            s = "<font color=red>Closed</font>"
        self.labelFlagOpenMarket.setText(s)


    @misc.CatchException
    @pyqtSignature("bool")
    def on_pushButtonForceOpen_clicked(self, checked):
        na.vala.flagOpenMarket = True
        self.UpdateGUI()

    @misc.CatchException
    @pyqtSignature("bool")
    def on_pushButtonForceClosed_clicked(self, checked):
        na.vala.flagOpenMarket = False
        self.UpdateGUI()
